/*
 * Copyright (C) 2014 Realtek Semiconductor Corp.
 * All Rights Reserved.
 *
 * This program is the proprietary software of Realtek Semiconductor
 * Corporation and/or its licensors, and only be used, duplicated,
 * modified or distributed under the authorized license from Realtek.
 *
 * ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
 * THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
 *
 * Purpose : Definition of ME handler: ONT2-G (257)
 *
 * Feature : The file includes the following modules and sub-modules
 *           (1) ME handler: ONT2-G (257)
 */

#include "app_basic.h"
#include "feature_mgmt.h"

MIB_TABLE_INFO_T gMibOnt2gTableInfo;
MIB_ATTR_INFO_T  gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_ATTR_NUM];
MIB_TABLE_ONT2G_T gMibOnt2gDefRow;
MIB_TABLE_OPER_T  gMibOnt2gOper;
#if (FTTR_1ST_SOL_DIS != 1)    
static GOS_ERROR_CODE onu2g_fttr_handler(UINT32 args_num, ...)
{
	GOS_ERROR_CODE		ret = GOS_OK;
	MIB_TABLE_ONT2G_T	*pOnt2g, *pOldOnt2g;
	va_list				ap;

	va_start(ap, args_num);

	void* pOldRow 					= va_arg(ap, void *);
    void* pNewRow 					= va_arg(ap, void *);
	MIB_OPERA_TYPE operationType 	= va_arg(ap, MIB_OPERA_TYPE);
	MIB_ATTRS_SET attrSet 			= va_arg(ap, MIB_ATTRS_SET);
	omci_msg_norm_t *pOmciNorMsg 	= va_arg(ap, omci_msg_norm_t *);

    va_end(ap);

	pOnt2g 		= (MIB_TABLE_ONT2G_T *)pNewRow;
	pOldOnt2g	= (MIB_TABLE_ONT2G_T *)pOldRow;
	
	OMCI_LOG(OMCI_LOG_LEVEL_INFO,
				"%s():%d, EntityID: 0x%02x, operationType=%u, attrSet=%x, mfuUniOpticalPid=%u, sfuID=%u", 
				__FUNCTION__, __LINE__,
				pOnt2g->EntityID,
				operationType, 
				attrSet, 
				pOmciNorMsg->mfuSfuId.mfuUniOpticalPid,
				pOmciNorMsg->mfuSfuId.sfuId);

    switch (operationType)
    {
		case MIB_GET:
		{
			if (MIB_IsInAttrSet(&attrSet, MIB_TABLE_ONT2G_VPCODE_INDEX))
			{
				#if 1
				omci_dm_fttr_onu_info_t dmFttrOnuInfo;
				memset(&dmFttrOnuInfo, 0, sizeof(omci_dm_fttr_onu_info_t));

				dmFttrOnuInfo.mfuPortId = pOmciNorMsg->mfuSfuId.mfuUniOpticalPid;
            	dmFttrOnuInfo.sfutId 	=  pOmciNorMsg->mfuSfuId.sfuId;

				if(FAL_OK == feature_api(FEATURE_API_FTTR_P2MP_GET, 
                                OMCI_DM_FTTR_CMD_GET_ONU_INFO_VPCODE, 
                                &dmFttrOnuInfo, 
                                sizeof(omci_dm_fttr_onu_info_t)))
				{
                    pOnt2g->VPCode = dmFttrOnuInfo.VPCode;
				    pOldOnt2g->VPCode = dmFttrOnuInfo.VPCode;
				} 
				#else
				/* self-debugging */

				pOnt2g->VPCode = 15;
				pOldOnt2g->VPCode = 15;

				#endif
			}

			if (MIB_IsInAttrSet(&attrSet, MIB_TABLE_ONT2G_EQTID_INDEX))
			{
				#if 1
				omci_dm_fttr_onu_info_t dmFttrOnuInfo;
				memset(&dmFttrOnuInfo, 0, sizeof(omci_dm_fttr_onu_info_t));

				dmFttrOnuInfo.mfuPortId = pOmciNorMsg->mfuSfuId.mfuUniOpticalPid;
            	dmFttrOnuInfo.sfutId 	=  pOmciNorMsg->mfuSfuId.sfuId;

				if(FAL_OK == feature_api(FEATURE_API_FTTR_P2MP_GET, 
                                OMCI_DM_FTTR_CMD_GET_ONU_INFO_EQT_ID, 
                                &dmFttrOnuInfo, 
                                sizeof(omci_dm_fttr_onu_info_t)))
				{
					strncpy(pOnt2g->EqtID, dmFttrOnuInfo.EqtID, MIB_TABLE_ONT2G_EQTID_LEN+1);
					strncpy(pOldOnt2g->EqtID, dmFttrOnuInfo.EqtID, MIB_TABLE_ONT2G_EQTID_LEN+1);
				} 
				#else
				/* self-debugging */
				
				strncpy(pOnt2g->EqtID, "CCCCCCCCCCCCCCCCCCCC", MIB_TABLE_ONT2G_EQTID_LEN+1);
				strncpy(pOldOnt2g->EqtID, "CCCCCCCCCCCCCCCCCCCC", MIB_TABLE_ONT2G_EQTID_LEN+1);

				#endif
			
			}
            if (MIB_IsInAttrSet(&attrSet, MIB_TABLE_ONT2G_SYSUPTIME_INDEX))
			{
				#if 1
				omci_dm_fttr_onu_info_t dmFttrOnuInfo;
				memset(&dmFttrOnuInfo, 0, sizeof(omci_dm_fttr_onu_info_t));

				dmFttrOnuInfo.mfuPortId = pOmciNorMsg->mfuSfuId.mfuUniOpticalPid;
            	dmFttrOnuInfo.sfutId 	=  pOmciNorMsg->mfuSfuId.sfuId;

				if(FAL_OK == feature_api(FEATURE_API_FTTR_P2MP_GET, 
                                OMCI_DM_FTTR_CMD_GET_ONU_INFO_SYS_UP_TIME, 
                                &dmFttrOnuInfo, 
                                sizeof(omci_dm_fttr_onu_info_t)))
				{
                    pOnt2g->SysUpTime = dmFttrOnuInfo.sysUpTime;
				    pOldOnt2g->SysUpTime = dmFttrOnuInfo.sysUpTime;
				} 
				#else
				/* self-debugging */
				
				pOnt2g->SysUpTime = 15;
				pOldOnt2g->SysUpTime = 15;

				#endif
			
			}
			OMCI_LOG(OMCI_LOG_LEVEL_INFO,
					"%s():%d, mfu_portid=%u, sfu_id=%u", 
					__FUNCTION__, __LINE__,
					pOmciNorMsg->mfuSfuId.mfuUniOpticalPid,
					pOmciNorMsg->mfuSfuId.sfuId);
			break;
		}
		default:
        	ret = GOS_OK;
            break;
    }

	return ret;
 
}
#endif


GOS_ERROR_CODE Ont2gDrvCfg(void             *pOldRow,
                            void            *pNewRow,
                            MIB_OPERA_TYPE  operationType,
                            MIB_ATTRS_SET   attrSet,
                            UINT32          pri)
{
    MIB_TABLE_INDEX     tableIndex = MIB_TABLE_ONT2G_INDEX;
    omci_me_instance_t  instanceID;
    MIB_TABLE_ONT2G_T *pMibOnt2g;

    // read out the instanceID
    MIB_GetAttrFromBuf(tableIndex,
        MIB_ATTR_FIRST_INDEX, &instanceID, pNewRow, sizeof(omci_me_instance_t));

    // read out the instanceID
	pMibOnt2g = (MIB_TABLE_ONT2G_T*)pNewRow;

    // only for status update
    {
        MIB_TABLE_ONT2G_T   mibOnu2G;

        mibOnu2G.EntityID = instanceID;

        // read out the entry data
        if (GOS_OK == MIB_Get(tableIndex, &mibOnu2G, sizeof(mibOnu2G)))
        {
            struct sysinfo  tSysInfo;
            unsigned long long tmpTime;
            if (!sysinfo(&tSysInfo))
            {
                tmpTime = tSysInfo.uptime;
		        tmpTime *= 100;
                // unit: 10 ms
                if (tmpTime > UINT_MAX)
                    // rolls over to 0 when full
                    mibOnu2G.SysUpTime = 0;
                else
                    mibOnu2G.SysUpTime = tSysInfo.uptime * 100;

                /*Update return value fo MIB GET*/
                pMibOnt2g->SysUpTime = mibOnu2G.SysUpTime;

                // invoke AVC callback and update attribute value
                MIB_Set(tableIndex, &mibOnu2G, sizeof(mibOnu2G));
            }
        }
    }

	return GOS_OK;
}

static GOS_ERROR_CODE onu2g_avc_cb(MIB_TABLE_INDEX  tableIndex,
                                    void            *pOldRow,
                                    void            *pNewRow,
                                    MIB_ATTRS_SET   *pAttrsSet,
                                    MIB_OPERA_TYPE  operationType)
{
    MIB_ATTR_INDEX      attrIndex;
    UINT32              i;
    MIB_ATTRS_SET       avcAttrSet;
    BOOL                isSuppressed;

    if (MIB_SET != operationType && MIB_ADD != operationType)
        return GOS_OK;

    if (!pNewRow || !pAttrsSet)
        return GOS_ERR_PARAM;

    // check if notifications are suppressed
    omci_is_notify_suppressed_by_circuitpack(0xFF, &isSuppressed);

    if (isSuppressed)
        MIB_ClearAttrSet(&avcAttrSet);
    else
    {
        avcAttrSet = *pAttrsSet;

        for (attrIndex = MIB_ATTR_FIRST_INDEX, i = 0;
                i < MIB_GetTableAttrNum(tableIndex); i++, attrIndex = MIB_ATTR_NEXT_INDEX(attrIndex))
        {
            if (!MIB_IsInAttrSet(pAttrsSet, attrIndex))
                continue;
        }
    }

    if (avcAttrSet != *pAttrsSet)
        *pAttrsSet = avcAttrSet;

    return GOS_OK;
}

GOS_ERROR_CODE mibTable_init(MIB_TABLE_INDEX tableId)
{
    gMibOnt2gTableInfo.Name = "Ont2g";
    gMibOnt2gTableInfo.ShortName = "ONT2G";
    gMibOnt2gTableInfo.Desc = "Ont2-g";
    gMibOnt2gTableInfo.ClassId = (UINT32)(OMCI_ME_CLASS_ONU2_G);
    gMibOnt2gTableInfo.InitType = (UINT32)(OMCI_ME_INIT_TYPE_ONU);
    gMibOnt2gTableInfo.StdType = (UINT32)(OMCI_ME_TYPE_STANDARD);
    gMibOnt2gTableInfo.ActionType = (UINT32)(OMCI_ME_ACTION_SET | OMCI_ME_ACTION_GET);
    gMibOnt2gTableInfo.pAttributes = &(gMibOnt2gAttrInfo[0]);
	gMibOnt2gTableInfo.attrNum = MIB_TABLE_ONT2G_ATTR_NUM;
	gMibOnt2gTableInfo.entrySize = sizeof(MIB_TABLE_ONT2G_T);
	gMibOnt2gTableInfo.pDefaultRow = &gMibOnt2gDefRow;

    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Name = "EntityID";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_EQTID_INDEX - MIB_TABLE_FIRST_INDEX].Name = "EqtID";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_OMCCVER_INDEX - MIB_TABLE_FIRST_INDEX].Name = "OMCCVer";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_VPCODE_INDEX - MIB_TABLE_FIRST_INDEX].Name = "VPCode";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECCAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].Name = "SecCapability";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECMODE_INDEX - MIB_TABLE_FIRST_INDEX].Name = "SecMode";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFPRIQ_INDEX - MIB_TABLE_FIRST_INDEX].Name = "NumOfPriQ";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFSCHEDULER_INDEX - MIB_TABLE_FIRST_INDEX].Name = "NumOfScheduler";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_MODE_INDEX - MIB_TABLE_FIRST_INDEX].Name = "Mode";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFGEMPORT_INDEX - MIB_TABLE_FIRST_INDEX].Name = "NumOfGemPort";
	gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SYSUPTIME_INDEX - MIB_TABLE_FIRST_INDEX].Name = "SysUpTime";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CONNECTIVITY_CAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].Name = "ConnectivityCapability";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CURRENT_CONNECTIVITY_MODE_INDEX - MIB_TABLE_FIRST_INDEX].Name = "CurrentConnectivityMode";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_QOS_CONFIGURATION_FLEXIBILITY_INDEX - MIB_TABLE_FIRST_INDEX].Name = "QosConfigurationFlexibility";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_PRIORITY_QUEUE_SCALE_FACTOR_INDEX - MIB_TABLE_FIRST_INDEX].Name = "PriorityQueueScaleFactor";

    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Entity ID";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_EQTID_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Equipment ID";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_OMCCVER_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "OMCC Version";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_VPCODE_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Vendor Product Code";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECCAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Security Capability";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECMODE_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Security Mode";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFPRIQ_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Total Priority Queue Number";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFSCHEDULER_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Total Traffic Scheduler Number";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_MODE_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Mode";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFGEMPORT_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Total GEM port-ID number";
	gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SYSUPTIME_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "System up time";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CONNECTIVITY_CAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Connectivity capability";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CURRENT_CONNECTIVITY_MODE_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Current connectivity mode";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_QOS_CONFIGURATION_FLEXIBILITY_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Qos configuration flexibility";
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_PRIORITY_QUEUE_SCALE_FACTOR_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Priority queue scale factor";

    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_EQTID_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_STR;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_OMCCVER_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_VPCODE_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECCAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECMODE_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFPRIQ_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFSCHEDULER_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_MODE_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFGEMPORT_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
	gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SYSUPTIME_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT32;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CONNECTIVITY_CAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CURRENT_CONNECTIVITY_MODE_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_QOS_CONFIGURATION_FLEXIBILITY_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_PRIORITY_QUEUE_SCALE_FACTOR_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;

    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_EQTID_INDEX - MIB_TABLE_FIRST_INDEX].Len = 20;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_OMCCVER_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_VPCODE_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECCAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECMODE_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFPRIQ_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFSCHEDULER_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_MODE_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFGEMPORT_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
	gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SYSUPTIME_INDEX - MIB_TABLE_FIRST_INDEX].Len = 4;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CONNECTIVITY_CAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CURRENT_CONNECTIVITY_MODE_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_QOS_CONFIGURATION_FLEXIBILITY_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_PRIORITY_QUEUE_SCALE_FACTOR_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;

    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_EQTID_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_OMCCVER_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_VPCODE_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECCAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECMODE_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFPRIQ_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFSCHEDULER_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_MODE_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFGEMPORT_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
	gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SYSUPTIME_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CONNECTIVITY_CAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CURRENT_CONNECTIVITY_MODE_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_QOS_CONFIGURATION_FLEXIBILITY_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_PRIORITY_QUEUE_SCALE_FACTOR_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;

    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_EQTID_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_OMCCVER_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_VPCODE_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECCAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECMODE_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFPRIQ_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFSCHEDULER_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_MODE_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFGEMPORT_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
	gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SYSUPTIME_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CONNECTIVITY_CAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CURRENT_CONNECTIVITY_MODE_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_QOS_CONFIGURATION_FLEXIBILITY_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_PRIORITY_QUEUE_SCALE_FACTOR_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;

    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_EQTID_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_CHAR;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_OMCCVER_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_VPCODE_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECCAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECMODE_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFPRIQ_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFSCHEDULER_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_MODE_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFGEMPORT_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
	gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SYSUPTIME_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CONNECTIVITY_CAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CURRENT_CONNECTIVITY_MODE_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_QOS_CONFIGURATION_FLEXIBILITY_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_PRIORITY_QUEUE_SCALE_FACTOR_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;

    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_EQTID_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_OMCCVER_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_VPCODE_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECCAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECMODE_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFPRIQ_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFSCHEDULER_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_MODE_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFGEMPORT_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
	gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SYSUPTIME_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CONNECTIVITY_CAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CURRENT_CONNECTIVITY_MODE_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_QOS_CONFIGURATION_FLEXIBILITY_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_PRIORITY_QUEUE_SCALE_FACTOR_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;

    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_EQTID_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_OMCCVER_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = TRUE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_VPCODE_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECCAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECMODE_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFPRIQ_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFSCHEDULER_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_MODE_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFGEMPORT_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
	gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SYSUPTIME_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CONNECTIVITY_CAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CURRENT_CONNECTIVITY_MODE_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_QOS_CONFIGURATION_FLEXIBILITY_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_PRIORITY_QUEUE_SCALE_FACTOR_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;

    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_EQTID_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_OPTIONAL;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_OMCCVER_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_VPCODE_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_OPTIONAL;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECCAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SECMODE_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFPRIQ_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFSCHEDULER_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_MODE_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_NUMOFGEMPORT_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_OPTIONAL;
	gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_SYSUPTIME_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_OPTIONAL;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CONNECTIVITY_CAPABILITY_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_OPTIONAL;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_CURRENT_CONNECTIVITY_MODE_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_OPTIONAL;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_QOS_CONFIGURATION_FLEXIBILITY_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_OPTIONAL;
    gMibOnt2gAttrInfo[MIB_TABLE_ONT2G_PRIORITY_QUEUE_SCALE_FACTOR_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_OPTIONAL;

    memset(&(gMibOnt2gDefRow.EntityID), 0x00, sizeof(gMibOnt2gDefRow.EntityID));
    memset(gMibOnt2gDefRow.EqtID, 0, MIB_TABLE_ONT2G_EQTID_LEN);
    gMibOnt2gDefRow.EqtID[MIB_TABLE_ONT2G_EQTID_LEN] = '\0';
    gMibOnt2gDefRow.OMCCVer = ONU2G_OMCC_VERSION_0x80; /*G.984.4 06/04*/
    memset(&(gMibOnt2gDefRow.VPCode), 0x00, sizeof(gMibOnt2gDefRow.VPCode));
    gMibOnt2gDefRow.SecCapability = MIB_ATTR_DEF_SPACE;
    gMibOnt2gDefRow.SecMode = MIB_ATTR_DEF_SPACE;
	gMibOnt2gDefRow.NumOfPriQ = 0;
    gMibOnt2gDefRow.NumOfScheduler = 0;
    gMibOnt2gDefRow.Mode = MIB_ATTR_DEF_SPACE;
    gMibOnt2gDefRow.NumOfGemPort = 0;
    gMibOnt2gDefRow.SysUpTime = 0;
    gMibOnt2gDefRow.ConnectivityCapability =
        ONU2G_CONNECTIVITY_CAPABILITY_N_TO_1 | ONU2G_CONNECTIVITY_CAPABILITY_1_TO_M |
        ONU2G_CONNECTIVITY_CAPABILITY_1_TO_P | ONU2G_CONNECTIVITY_CAPABILITY_N_TO_M |
        ONU2G_CONNECTIVITY_CAPABILITY_1_TO_MP | ONU2G_CONNECTIVITY_CAPABILITY_N_TO_P |
        ONU2G_CONNECTIVITY_CAPABILITY_N_TO_MP;
    gMibOnt2gDefRow.CurrentConnectivityMode = ONU2G_CURRENT_CONNECTIVITY_MODE_DEFAULT;
    gMibOnt2gDefRow.QosConfigurationFlexibility =
        ONU2G_QOS_CFG_PQ_RELATED_PORT_PORT_RW | ONU2G_QOS_CFG_PQ_TRAFFIC_SCHEDULER_RW |
        ONU2G_QOS_CFG_PQ_RELATED_PORT_PRIORITY_RW | ONU2G_QOS_CFG_TS_POLICY_RW | ONU2G_QOS_CFG_TC_POLICY_RW;
    gMibOnt2gDefRow.PriorityQueueScaleFactor = 1;

    memset(&gMibOnt2gOper, 0x0, sizeof(MIB_TABLE_OPER_T));
	gMibOnt2gOper.meOperDrvCfg = Ont2gDrvCfg;
	gMibOnt2gOper.meOperConnCheck = NULL;
	gMibOnt2gOper.meOperDump = omci_mib_oper_dump_default_handler;
	gMibOnt2gOper.meOperConnCfg = NULL;
#if (FTTR_1ST_SOL_DIS != 1)    
    gMibOnt2gOper.meOperCb[OMCI_MIB_CB_FTTR_SFU] = onu2g_fttr_handler;
#endif
	MIB_TABLE_ONT2G_INDEX = tableId;
	MIB_InfoRegister(tableId,&gMibOnt2gTableInfo,&gMibOnt2gOper);
    MIB_RegisterCallback(tableId, NULL, onu2g_avc_cb);

    return GOS_OK;
}
